local jiang = fk.CreateSkill {
  name = "lvshi__old_jiang",
}

Fk:loadTranslationTable{
  ["lvshi__old_jiang"] = "激昂",
  [":lvshi__old_jiang"] = "当你使用伤害类牌指定目标/成为伤害类牌的目标后，若目标为1，你可令目标角色交给你一张牌/摸一张牌并展示之，若颜色相同，则你须弃置一张牌，且你可使用以此法弃置的【杀】。",
  ["#lvshi__old_jiang-invoke"] = "激昂：你可令%src交给你一张牌",
  ["#lvshi__old_jiang-give"] = "激昂：你须交给%src一张牌",
  ["#lvshi__old_jiang-discard"] = "激昂：你须弃置一张牌",
  ["#lvshi__old_jiang-use"] = "激昂：你可使用此【杀】。",
}

jiang:addEffect(fk.AfterCardTargetDeclared, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jiang.name) and data.card.is_damage_card and data:isOnlyTarget(data.tos[1])
    and not data.tos[1]:isNude()
  end,
  on_use = function(self, event, target, player, data)
    local to = data.tos[1]
    local room = player.room
    local card = room:askToCards(to, {
      skill_name = jiang.name,
      include_equip = true,
      min_num = 1,
      max_num = 1,
      prompt = "#lvshi__old_jiang-give:"..player.id,
      cancelable = false,
    })
    if #card > 0 then
      room:obtainCard(player, card, false, fk.ReasonGive, to, jiang.name)
      player:showCards(card)
      if Fk:getCardById(card[1]):compareColorWith(data.card) and not player:isNude() then
        local result = player.room:askToDiscard(player, {
          min_num = 1,
          max_num = 1,
          include_equip = true,
          skill_name = jiang.name,
          cancelable = false,
          prompt = "#lvshi__old_jiang-discard",
        })
        local slash = table.filter(result, function (id)
          return Fk:getCardById(id).trueName == "slash"
        end)
        if #slash > 0 then
          player.room:askToUseRealCard(player, {
            pattern = slash,
            skill_name = jiang.name,
            prompt = "#lvshi__old_jiang-use",
            extra_data = { expand_pile = slash },
          })
        end
      end
    end
  end,
})

jiang:addEffect(fk.TargetConfirmed, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(jiang.name) and data.card.is_damage_card and data:isOnlyTarget(player)
  end,
  on_use = function(self, event, target, player, data)
    local ids = player:drawCards(1, jiang.name)
    player:showCards(ids)
    if Fk:getCardById(ids[1]):compareColorWith(data.card) and not player:isNude() then
      local result = player.room:askToDiscard(player, {
        min_num = 1,
        max_num = 1,
        include_equip = true,
        skill_name = jiang.name,
        cancelable = false,
        prompt = "#lvshi__old_jiang-discard",
      })
      local slash = table.filter(result, function (id)
        return Fk:getCardById(id).trueName == "slash"
      end)
      if #slash > 0 then
        player.room:askToUseRealCard(player, {
          pattern = slash,
          skill_name = jiang.name,
          prompt = "#lvshi__old_jiang-use",
          extra_data = { expand_pile = slash },
        })
      end
    end
  end,
})

return jiang
